#include <iostream>
using namespace std;
string s , t;

int T;
void solve()
{
    cin >> t >> s;
    int ans = 0;
    int len = s.size();
    for(int i = 0;i < len;i ++)
    {
        if(s[i] != t[i])
        {
            if(i == 0 || i == len - 1)
            {
                cout << -1 << endl;
                return;
            }
            if(s[i] != s[i -1] && s[i] != s[i + 1])
            {
                ans ++;
                s[i] = s[i] == '1' ? '0' : '1';
            }
        }
    }
    if(s == t)
    {
        cout << ans << endl;
        return;
    }
    cout << -1 << endl;
}
int main()
{
    cin >> T;
    while(T--)
    {
        solve();
    }
    return 0;
}